<template>
	<view class="content">
		<view class="mimatishi">密码不少于6位，至少包含字母/数字/符号2种组合</view>
		<view class="inputbkc">
			<input v-model.trim="password" class="password" focus placeholder="新密码(最少6位数)" password="true"/>
			<view class="line"></view>
			<input v-model.trim="querenpassword" class="querenpassword" placeholder="再次确认" password="true"/>
		</view>
		<view>
			<button class="btn" type="default" @click="setmima">确定</button>			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				password: '',
				querenpassword: '',
				uid: '',
			}
		},
		onLoad(option) {
			this.uid = option.uid;
		},
		methods: {
			// 设置密码
			setmima() {
				if(this.password == '') {
					uni.showToast({
					    title: '密码不能为空',
						icon: 'none',
					    duration: 2000
					});
					return;
				}
				if(this.password.length < 6)  {
					uni.showToast({
					    title: '密码长度不能少于6个字符',
						icon: 'none',
					    duration: 2000
					});
					return;
				}
				if(this.password != this.querenpassword) {
					uni.showToast({
					    title: '两次输入密码不同',
						icon: 'none',
					    duration: 2000
					});
					return;
				}
				// 设置密码
				uni.request({
				    url: 'https://www.yedushu.cn/api/setmima',  // 设置保存密码
				    data: {
				        password: this.password,
						uid: this.uid
				    },
					method: 'POST',
				    success: (res) => {
						console.log(JSON.stringify(res));
						// uni.showToast({
						//     title: '密码修改成功',
						// 	icon: 'none',
						//     duration: 2000
						// });
						if(res.data.code == 1){
							// 密码修改成功，返回上一页
							uni.navigateBack({
							    delta: 1
							});
						}
				    }
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		padding: 10px 10px;
	}
	.mimatishi {
		padding: 5px 7px;
		color: #b2b2b2;
		font-size: 14px;
	}
	.inputbkc {
		margin: 10px 0;
		border: 1px solid #b2b2b2;
		padding: 7px 7px;
		border-radius: 7px;
	}
	.password {
		padding: 10px 0;
		font-size: 15px;
	}
	.line {
		border-bottom: 1px solid #b2b2b2;
	}
	.querenpassword {
		padding: 10px 0;
		font-size: 15px;
	}
	.btn {
		background-color: #00cc33;
		color: #FFFFFF;
	}
</style>
